// 解构赋值

const panda = {
    id: 5008,
    name: '大美',
    age: 5
}

console.log( panda.id, panda.name, panda.age );

/*
// 被赋值的变量名恰好与对象中的属性名相同
const id = panda.id;
const name = panda.name;
const age = panda.age ;
*/

// 解构对象并将其属性值赋值给相应变量
const { id, name , age } = panda ;
console.log( id, name, age );

console.log( '- '.repeat(10) );

const girl = {
    id: 1001,
    name: '阿芳',
    gender: '女',
    age: 20
}

// cosnt { 属性名: 变量名 [, ...] } = 对象;
const { id: gid, name: gname, age: gage, gender } = girl ;
console.log( gid, gname, gage, gender );

console.log( '- '.repeat(10) );

const names = [ '王某然', '菲尔娜', '李小芳', '罗丹丹' ];
// 解构数组并将数组中各元素值依次赋值给相应变量
const [ first, second, third, fourth ] = names;
console.log( first );
console.log( second );
console.log( third );
console.log( fourth );